<?php 
/**
 * 后台用户表模型
 */
class AdminModel extends Model{
	public $table = 'admin';
	//自动验证
	public $validate = array(
		//用户名验证
		array('username','nonull','用户名不能为空',2,3),
		//密码验证
		array('password','nonull','密码不能为空',2,3),
		//验证码
		array('code','nonull','验证不能为空',2,3)
	);
	//登录方法
	public function login(){
		//执行验证
		if(!$this->create()) return false;
		//用户名和密码匹配
		$username = Q('post.username');
		$userInfor = $this->where("username='{$username}'")->find();
		if(!$userInfor || $userInfor['password']!=md5(Q('post.password'))){
			$this->error = '用户名或者密码错误';
			return false;
		}
		return $userInfor;
	}
	
}











 ?>